package longcaisuyun.longcai.com.yiliubabalongcaisuyun;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import longcaisuyun.longcai.com.suyunbean.DingDanPaiHangBang;



/**
 * Created by Administrator on 2016/2/19.
 */
public class PaiHangAdapter extends BaseAdapter {
    Context context;
    ViewHolder vh;
    DingDanPaiHangBang dingDanPaiHangBang;
    private int j=0;
    private List<DingDanPaiHangBang.ListBean> list=new ArrayList<>();
    public PaiHangAdapter(Context context, DingDanPaiHangBang dingDanPaiHangBang) {
        this.context = context;
        //对传过来的list进行重新排序
        this.dingDanPaiHangBang=dingDanPaiHangBang;
//        for (int i = 0; i <; i--) {
//            list.add(this.dingDanPaiHangBang.getList().get(i));
//        }
//        Log.e("list有多少",list.size()+"");
    }

    public int getCount() {
        return dingDanPaiHangBang.getList().size();
    }

    @Override
    public Object getItem(int position) {
        return dingDanPaiHangBang.getList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_paihang, null);
            MyApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            vh.b = (Button) convertView.findViewById(R.id.b_num);
            vh.tv_1 = (TextView) convertView.findViewById(R.id.tv_name);
            vh.tv_2 = (TextView) convertView.findViewById(R.id.tv_num);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_1.setText(dingDanPaiHangBang.getList().get(position).getUsername());
        vh.tv_2.setText(dingDanPaiHangBang.getList().get(position).getNumber());
        vh.b.setText(String.valueOf(position + 1));
        return convertView;
    }

    class ViewHolder {
        public Button b;
        public TextView tv_1;
        public TextView tv_2;
    }
}
